<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020-08-14 16:31:07
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\AdminBaseController;
use think\Exception;
use think\facade\Db;
use think\facade\Route;
use think\Request;
use app\admin\model\ArticleComments;
use app\admin\service\ExcelService;
use app\admin\model\ArticleUsers;

class ArticleComment extends AdminBaseController
{

    protected function initialize()
   {
           parent::initialize(); // TODO: Change the autogenerated stub

           $this->model = new ArticleComments();
           $this->assign("user",ArticleUsers::where("status","=",1)->select()->toArray());
    }



   /**
     * @param Request $request
     * @return string|\think\response\Json
     * @author: Hhy <jackhhy520@qq.com>
     * @describe:添加
     */
    public function add(Request $request){
        if (IS_AJAX) {
            $data = $request->post();
            try{

                return $this->model->doAll($data);

            }catch (Exception $exception){
                return parent::JsonReturn($exception->getMessage(), 0);
            }
        }


        return $this->fetch();
    }


    /**
     * @param $id
     * @return string|\think\response\Json
     * @author: Hhy <jackhhy520@qq.com>
     * @describe:编辑
     */
    public function edit($id){

        $info=$this->model->where("id",$id)->find()->toArray();
        if (!$info){
            return parent::failed("未查询到数据");
        }
        $this->assign(compact("info"));
        return $this->fetch();
    }



    /**
     * @return \think\response\Json
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @describe:评论审核
     */
    public function check()
    {
        if (IS_AJAX) {
            $data = $this->request->post();
            try {
                if (is_array($data['ids'])) {
                    $id = $data['ids'];
                } else {
                    $id = @explode(",", $data['ids']);
                }
                $res = $this->model->where("id", "in", $id)->update(['status' => 1, 'is_show' => $data['is_show']]);
                if ($res){
                    return parent::JsonReturn("审核成功");
                }else{
                    return parent::JsonReturn("审核失败", 0);
                }
            } catch (Exception $exception) {
                return parent::JsonReturn($exception->getMessage(), 0);
            }
        }
    }


}